<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveSupport::Notifications::Instrumenter</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActiveSupport::Notifications::Instrumenter 
            
                <span class="parent">&lt; 
                    
                    <a href="../../Object.html">Object</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/activesupport/lib/active_support/notifications/instrumenter_rb.html">activesupport/lib/active_support/notifications/instrumenter.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>Instrumenters are stored in a thread local.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>F</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Instrumenter.html#method-i-finish">finish</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>I</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Instrumenter.html#method-i-instrument">instrument</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Instrumenter.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Instrumenter.html#method-i-start">start</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    
      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>id</td>
            <td class='attr-desc'></td>
          </tr>
        
      </table>
    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(notifier)
            
            <a href="Instrumenter.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/6d8c070821bc846eb263b8c045ae652ebd751569/activesupport/lib/active_support/notifications/instrumenter.rb#L9" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/instrumenter.rb, line 9</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">notifier</span>)
  <span class="ruby-ivar">@id</span>       = <span class="ruby-identifier">unique_id</span>
  <span class="ruby-ivar">@notifier</span> = <span class="ruby-identifier">notifier</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-finish">
            
              <b>finish</b>(name, payload)
            
            <a href="Instrumenter.html#method-i-finish" name="method-i-finish" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Send a finish notification with <code>name</code> and <code>payload</code>.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-finish_source')" id="l_method-i-finish_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/6d8c070821bc846eb263b8c045ae652ebd751569/activesupport/lib/active_support/notifications/instrumenter.rb#L35" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-finish_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/instrumenter.rb, line 35</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">finish</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">payload</span>)
  <span class="ruby-ivar">@notifier</span>.<span class="ruby-identifier">finish</span> <span class="ruby-identifier">name</span>, <span class="ruby-ivar">@id</span>, <span class="ruby-identifier">payload</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-instrument">
            
              <b>instrument</b>(name, payload={})
            
            <a href="Instrumenter.html#method-i-instrument" name="method-i-instrument" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Instrument the given block by measuring the time taken to execute it and
publish it. Notice that events get sent even if an error occurs in the
passed-in block.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-instrument_source')" id="l_method-i-instrument_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/6d8c070821bc846eb263b8c045ae652ebd751569/activesupport/lib/active_support/notifications/instrumenter.rb#L17" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-instrument_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/instrumenter.rb, line 17</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">instrument</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">payload</span>={})
  <span class="ruby-identifier">start</span> <span class="ruby-identifier">name</span>, <span class="ruby-identifier">payload</span>
  <span class="ruby-keyword">begin</span>
    <span class="ruby-keyword">yield</span> <span class="ruby-identifier">payload</span>
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
    <span class="ruby-identifier">payload</span>[<span class="ruby-value">:exception</span>] = [<span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>]
    <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>
  <span class="ruby-keyword">ensure</span>
    <span class="ruby-identifier">finish</span> <span class="ruby-identifier">name</span>, <span class="ruby-identifier">payload</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-start">
            
              <b>start</b>(name, payload)
            
            <a href="Instrumenter.html#method-i-start" name="method-i-start" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Send a start notification with <code>name</code> and <code>payload</code>.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-start_source')" id="l_method-i-start_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/6d8c070821bc846eb263b8c045ae652ebd751569/activesupport/lib/active_support/notifications/instrumenter.rb#L30" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-start_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/notifications/instrumenter.rb, line 30</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">start</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">payload</span>)
  <span class="ruby-ivar">@notifier</span>.<span class="ruby-identifier">start</span> <span class="ruby-identifier">name</span>, <span class="ruby-ivar">@id</span>, <span class="ruby-identifier">payload</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    